app.controller('userController', function($scope, $controller,$filter, baseService){
    // 继承基础控制器
    $controller('baseController',{$scope:$scope});


    // 1.查询所有
    $scope.findAll=function () {
        baseService.sendGet("/user/findAll").then(function (value) {
            $scope.dataList= value.data;
        })
    }

    // 2.多条件查询
    $scope.search=function (page,rows) {
        baseService.findByPage("/user/findByPage",page,rows,$scope.user).then(function (value) {
            $scope.dataList = value.data.list;
            for (var i=0;i<$scope.dataList.length;i++){
                $scope.dataList[i].brithday=$filter("date")( $scope.dataList[i].brithday, "yyyy-MM-dd ")
                $scope.dataList[i].createTime=$filter("date")( $scope.dataList[i].createTime, "yyyy-MM-dd ")
            }
            $scope.paginationConf.totalItems= value.data.totalItems;//设置分页总数


        })

    }


    // 3.根据id批量删除
    $scope.deleteByid=function () {
        baseService.deleteById("/user/delete",  $scope.ids).then(function (response) {
            if (response.data) {
                alert("删除成功")
                // 重新加载
                $scope.reload();
            }else {
                alert("删除失败")
            }

        })
    }

    // 4.新建或更新
    //      选择性别
    $scope.checkSex=function (value) {
        $scope.entity.sex=value;
    }
    $scope.isCheck=function (value) {
        return  $scope.entity.sex==value
    }
    $scope.updateOrSave=function (entity) {
        var url="save"
        if(entity.id){
            url="update"
        }
        baseService.sendPost("/user/"+url,$scope.entity).then(function (response) {
            if (response.data) {
                alert("添加或更新成功")
                $scope.reload();


            }else {
                alert("添加或更新失败")
            }
        })

    }

    // 5.数据回显
    $scope.show = function(entity){
        /** 把json对象转化成一个新的json对象 */
        $scope.entity = JSON.parse(JSON.stringify(entity));
    };



})